package swing;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import ViewObjects.ItemAlmacenView;

import rmi.ProxyModeloConcreto;

import controlador.Controlador;
import controlador.ControladorAdmStock;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class StockConsulta extends Vista{
	private JLabel jLabelcodifgoSfk;
	private JLabel jLabelCantidad;
	private JLabel jLabelPrecioU;
	private JButton jButtonLimpiar;
	private JButton jButtonBuscar;
	private JButton jButtonCancelar;
	private JButton jLabelMensaje;
	private JTextField jTextFieldPrecioU;
	private JTextField jTextFieldCantidad;
	private JTextField jTextFieldicodigoSfk;

	public StockConsulta(){
		super();
		initGUI();
	}
	
	@Override
	public void actualizar() {
		// TODO Auto-generated method stub
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Consultar Stock");
			this.setVisible(true);

			{
				jLabelcodifgoSfk = new JLabel();
				getContentPane().add(jLabelcodifgoSfk, BorderLayout.CENTER);
				jLabelcodifgoSfk.setText("Codigo SFK: ");
				jLabelcodifgoSfk.setBounds(17, 29, 145, 27);
			}
			{
				jLabelCantidad = new JLabel();
				getContentPane().add(jLabelCantidad);
				jLabelCantidad.setText("Cantidad : ");
				jLabelCantidad.setBounds(17, 77, 183, 16);
			}
			{
				jLabelPrecioU = new JLabel();
				getContentPane().add(jLabelPrecioU);
				jLabelPrecioU.setText("Precio Unitario : ");
				jLabelPrecioU.setBounds(17, 122, 165, 16);
			}
			{
				jTextFieldicodigoSfk = new JTextField();
				getContentPane().add(jTextFieldicodigoSfk);
				jTextFieldicodigoSfk.setBounds(114, 31, 94, 23);
			}
			{
				jTextFieldCantidad = new JTextField();
				getContentPane().add(jTextFieldCantidad);
				jTextFieldCantidad.setBounds(114, 74, 90, 23);
			}
			{
				jTextFieldPrecioU = new JTextField();
				getContentPane().add(jTextFieldPrecioU);
				jTextFieldPrecioU.setBounds(115, 119, 86, 23);
			}
			{
				jButtonCancelar = new JButton();
				getContentPane().add(jButtonCancelar);
				jButtonCancelar.setText("Cancelar");
				jButtonCancelar.setBounds(222, 241, 91, 23);
				jButtonCancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						dispose();
						}	
					} 
				);
			}
			{
				jButtonBuscar = new JButton();
				getContentPane().add(jButtonBuscar);
				jButtonBuscar.setText("Buscar");
				jButtonBuscar.setBounds(220, 31, 85, 23);
				jButtonBuscar.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) 
				{
					buscarStock();
					}
				});

			}
			{
				jButtonLimpiar = new JButton();
				getContentPane().add(jButtonLimpiar);
				jButtonLimpiar.setText("Limpiar");
				jButtonLimpiar.setBounds(222, 198, 91, 23);
				jButtonLimpiar.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) 
				{
					
					jTextFieldPrecioU.setText("");
					jTextFieldCantidad.setText("");
					jTextFieldicodigoSfk.setText("");
					
					
					
					}
				});
			}
			{
				this.setSize(363, 313);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private void buscarStock() {
		ProxyModeloConcreto p = (ProxyModeloConcreto) controlador.getModelo();
		ItemAlmacenView irw = p.buscarItemAlmacen(jTextFieldicodigoSfk.getText());
		
		if (irw!=null){
			jTextFieldCantidad.setText(Integer.toString((irw.getCantStock())));
			jTextFieldicodigoSfk.setText((Float.toString(irw.getPrecioUnitario())));
			
		} else {
			jLabelMensaje.setText("El Codigo no Existe");
		}
	}
	
	
}
